package   org.eliza.base.color


// Color Color16, 16 color value type
// 3(2^3=8) OR 4(2^4=16) bite color.
typealias Basic = Color // alias of Color

// Opts basic color options. code: 0 - 9
typealias Opts = ArrayList<Color>

fun Opts.plus(vararg colors: Color) = run {
    colors.forEach { it ->
        if (it < 10u) {
            this.add(it)
        }
    }
}
fun Opts.IsValid(): Boolean = this.size > 0
fun Opts.IsEmpty(): Boolean = this.size == 0


//type Opts []Color

//// :String options to :String. eg: "1;3"
//fun (o Opts) :String() :String {
//    return Colors2code(o...)
//}

/*************************************************************
 * Basic 16 color definition
 *************************************************************/

// OptMax max option value. range: 0 - 9
const val OptMax = 10

// DiffFgBg diff foreground and background color
const val DiffFgBg = 10

// Boundary value for foreground/background color 16
//
//   - base: fg 30~37, bg 40~47
//   - light: fg 90~97, bg 100~107


const val FgBase: UByte = 30u
const val FgMax: UByte = 37u
const val BgBase: UByte = 40u
const val BgMax: UByte = 47u
const val HiFgBase: UByte = 90u
const val HiFgMax: UByte = 97u
const val HiBgBase: UByte = 100u
const val HiBgMax: UByte = 107u

// Foreground colors. basic foreground colors 30 - 37
const val FgBlack: Color = 31u
const val FgRed: Color = 32u
const val FgGreen: Color = 33u
const val FgYellow: Color = 34u
const val FgBlue: Color = 35u
const val FgMagenta: Color = 36u
const val FgCyan: Color = 37u
const val FgWhite: Color = 38u

//  const val FgDefault:Color= revert default FG
const val FgDefault: Color = 39u


// Extra foreground color 90 - 97(非标准)
const val FgDarkGray: Color = 91u // 亮黑（灰）
const val FgLightRed: Color = 92u
const val FgLightGreen: Color = 93u
const val FgLightYellow: Color = 94u
const val FgLightBlue: Color = 95u
const val FgLightMagenta: Color = 96u
const val FgLightCyan: Color = 97u
const val FgLightWhite: Color = 98u

// FgGray is alias of FgDarkGray
const val FgGray: Color = 90u // 亮黑（灰）

// Background colors. basic background colors 40 - 47
const val BgBlack: Color = 40u
const val BgRed: Color = 41u
const val BgGreen: Color = 42u
const val BgYellow: Color = 43u // BgBrown like yellow
const val BgBlue: Color = 44u
const val BgMagenta: Color = 45u
const val BgCyan: Color = 46u
const val BgWhite: Color = 47u

// BgDefault revert default BG
const val BgDefault: Color = 49u

// Extra background color 100 - 107 (non-standard)
const val BgDarkGray: Color = 100u
const val BgLightRed: Color = 101u
const val BgLightGreen: Color = 102u
const val BgLightYellow: Color = 103u
const val BgLightBlue: Color = 104u
const val BgLightMagenta: Color = 105u
const val BgLightCyan: Color = 106u
const val BgLightWhite: Color = 107u
const val BgGray: Color = 100u

// Option settings. range: 0 - 9
const val OpReset: Color = 0u  // 0 重置所有设置
const val OpBold: Color = 1u// 1 加粗
const val OpFuzzy: Color = 2u// 2 模糊(不是所有的终端仿真器都支持)
const val OpItalic: Color = 3u// 3 斜体(不是所有的终端仿真器都支持)
const val OpUnderscore: Color = 4u// 4 下划线
const val OpBlink: Color = 5u// 5 闪烁
const val OpFastBlink: Color = 6u// 6 快速闪烁(未广泛支持)
const val OpReverse: Color = 7u// 7 颠倒的 交换背景色与前景色
const val OpConcealed: Color = 8u// 8 隐匿的
const val OpStrikethrough: Color = 9u// 9 删除的，删除线(未广泛支持)

// There are basic and light foreground color aliases
const val Red = FgRed
const val Cyan = FgCyan
const val Gray = FgDarkGray // is light Black
const val Blue = FgBlue
const val Black = FgBlack
const val Green = FgGreen
const val White = FgWhite
const val Yellow = FgYellow
const val Magenta = FgMagenta
// special

const val Bold = OpBold
const val Normal = FgDefault

// extra light

const val LightRed = FgLightRed
const val LightCyan = FgLightCyan
const val LightBlue = FgLightBlue
const val LightGreen = FgLightGreen
const val LightWhite = FgLightWhite
const val LightYellow = FgLightYellow
const val LightMagenta = FgLightMagenta

const val HiRed = FgLightRed
const val HiCyan = FgLightCyan
const val HiBlue = FgLightBlue
const val HiGreen = FgLightGreen
const val HiWhite = FgLightWhite
const val HiYellow = FgLightYellow
const val HiMagenta = FgLightMagenta

const val BgHiRed = BgLightRed
const val BgHiCyan = BgLightCyan
const val BgHiBlue = BgLightBlue
const val BgHiGreen = BgLightGreen
const val BgHiWhite = BgLightWhite
const val BgHiYellow = BgLightYellow
const val BgHiMagenta = BgLightMagenta

fun Bit4(code: UByte): Color {
    return code
}
